<template>
	<view class="ljapp">
		<scroll-view class="head" scroll-x="true">
			<view v-for="(item,index) in headlist" :key="index" class="head_list" @click="Onhead(item)">
				<view :class="code == item.code?'hig':''">{{item.title}}</view>
				<view :class="code == item.code?'hig_border1':''"></view>
			</view>
		</scroll-view>
		<view class="content">
			<!-- 数据 -->
			<LoadMore ref="LoadMore" id="LoadMore" :diffHeight="100" :initData="initData" @dataRefresh='dataRefresh'>
				<text></text>
				<view v-for="(item,index) in MessageList" :key="index" class="card_box">
					<view class="flex-row-between">
						<view class="font14 flex-row-start">
							<view class="font-969696 w100p" style="margin-right: 4rpx;">就诊人:</view>
							<view>{{item.user_the_patient.name}} {{item.user_the_patient.sex ==1 ?'男':'女'}}</view>
						</view>
						<view style="color: #F8A538;" class="font14">{{item.typename}}</view>
					</view>
					<view class="font14 flex-row-start" style="margin-top: 10rpx;">
						<view class="font-969696 w100p" style="margin-right: 4rpx;">订单号:</view>
						<view class="flex-1">{{item.order_code}}</view>
					</view>
					<view class="font14 flex-row-start" style="margin-top: 10rpx;">
						<view class="font-969696 w100p" style="margin-right: 4rpx;">下单时间:</view>
						<view class="flex-1">
							{{$base.formatTime(new Date(item.createtime * 1000), 'yyyy-MM-dd hh:mm:ss')}}
						</view>
					</view>
					<view v-if="item.report_filename" class="font14 flex-row-start" style="margin-top: 10rpx;">
						<view class="font-969696 w100p">解读报告—</view>
						<view @click.stop="onFtp(item)" class="flex-1 underline" style="color: #00B7EE;">{{item.report_filename}}</view>
					</view>
					<view class="flex-row-between info_bottom">
						<view class="font-323232 font14">订单金额:¥{{item.money?item.money:'-'}}</view>	
						<view v-if="item.pay_status==2&&item.status=='normal'" class="btn flex-row-center" @click.stop="Onpages('/pagesA/ask/payment?id='+item.order_code+'&type=report')">去支付</view>
						<view v-else class="btn flex-row-center" @click="Onpages('/pagesA/message/chat?isDoc=0&cate=report&orderno='+item.order_code)">订单详情</view>
					</view>	
				</view>
			</LoadMore>
		</view>
	</view>
</template>

<script>
	import LoadMore from "@/components/loadMore.vue";
	export default {
		components: {
			LoadMore
		},
		data() {
			return {
				// group:{
				// 	page: 1,
				// 	limit: 10,
				// 	list: [],
				// 	loaded: false
				// },
				// loading: false,

				code: 'normal1',
				http_img: this.$store.state.http_img, //图片地址
				//头部列表
				headlist: [{
						title: '待支付',
						id: 1,
						code: 'normal1',
					},
					{
						title: '待接诊',
						id: 2,
						code: 'normal2'
					},
					{
						title: '已接诊',
						id: 3,
						code: 'patient'
					},
					{
						title: '已拒诊',
						id: 8,
						code: 'refuse_patient'
					},
					{
						title: '已结束',
						id: 4,
						code: 'end',
					},
					{
						title: '已评论',
						id: 5,
						code: 'comment',
					},
					{
						title: '已取消',
						id: 6,
						code: 'cancel',
					},
					{
						title: '已退款',
						id: 7,
						code: 'refund',
					}
				],
				//传参数据
				initData: {
					url: 'listConsultationReportOrder', //接口
					//data里得传参
					param: {
						pay_status: '2',
						status: 'normal1'
					},
				},
				MessageList: []
			}
		},
		onLoad: function(options) {
			if (options.type == 1) {
				this.initData.param.pay_status = 1
				this.initData.param.status = 'normal'
				this.code = 'normal2'
			}
		},
		methods: {
			//返回数据
			dataRefresh(e) {
				e.forEach(item => {
					if (item.pay_status == 2) {
						if (item.status == 'normal') {
							item.typename = '待支付'
						}
						if (item.status == 'cancel') {
							item.typename = '已取消'
						}
					} else if (item.pay_status == 1) {
						if (item.status == 'normal') {
							item.typename = '待接诊'
						}
						if (item.status == 'patient') {
							item.typename = '已接诊'
						}
						if (item.status == 'refuse_patient') {
							item.typename = '已拒诊'
						}
						if (item.status == 'end') {
							item.typename = '待评价'
						}
						if (item.status == 'comment') {
							item.typename = '已结束'
						}
						if (item.status == 'cancel') {
							item.typename = '已取消'
						}
						if (item.status == 'refund') {
							item.typename = '已退款'
						}
					}
					// item.createtime = this.$base.formatTime(new Date(item.createtime *
					// 	1000), "yyyy/MM/dd hh:mm:ss")
				})
				this.MessageList = e
			},
			//切换
			Onhead(res) {
				if (res.code == 'normal1') {
					this.initData.param.pay_status = 2
					this.initData.param.status = 'normal'
				}
				if (res.code == 'normal2') {
					this.initData.param.pay_status = 1
					this.initData.param.status = 'normal'
				}
				if (res.code == 'patient') {
					this.initData.param.pay_status = 1
					this.initData.param.status = 'patient'
				}
				if (res.code == 'refuse_patient') {
					this.initData.param.pay_status = 1
					this.initData.param.status = 'refuse_patient'
				}
				if (res.code == 'end') {
					this.initData.param.pay_status = 1
					this.initData.param.status = 'end'
				}
				if (res.code == 'comment') {
					this.initData.param.pay_status = 1
					this.initData.param.status = 'comment'
				}
				if (res.code == 'cancel') {
					this.initData.param.pay_status = ''
					this.initData.param.status = 'cancel'
				}
				if (res.code == 'refund') {
					this.initData.param.pay_status = 1
					this.initData.param.status = 'refund'
				}
				this.MessageList = []
				this.code = res.code
				this.$refs.LoadMore.oncutRefresh(this.initData)
			},
			//页面跳转
			Onpages(e) {
				uni.navigateTo({
					url: e,
				})
			},
			onFtp(item){
				let that = this
				wx.downloadFile({ //将文档下载到本地
					url: item.report_url, //pdf链接
					filePath: wx.env.USER_DATA_PATH + '/' + item.report_filename, // 需要预览文件的名称
					success(res) {
						wx.openDocument({ //打开文档
							filePath: res.filePath, //本地文档路径
							fileType: "pdf", //文档类型
							showMenu: true,
							success: function(res) {
								wx.showToast({
									title: '打开文档成功',
								})
							},
							fail: function(res) {
								wx.showToast({
									title: '打开文档失败',
								})
							},
						})
					},
				})
			},
		}
	}
</script>

<style lang="less">
	.ljapp {
		background: #F6F6F6;
		width: 750rpx;
		height: 100%;

		.head {
			width: 750rpx;
			height: 88rpx;
			background: #FFFFFF;
			white-space: nowrap;
			padding: 0 35rpx;

			.head_list {
				display: inline-block;
				width: 110rpx;
				color: #666666;
				font-size: 30rpx;
				line-height: 88rpx;
				position: relative;
				height: 88rpx;
				text-align: center;

				.hig {
					color: #00B7EE
				}

				.hig_border1 {
					width: 54rpx;
					height: 6rpx;
					background: #00B7EE;
					border-radius: 3rpx;
					position: absolute;
					bottom: 0;
					left: 28rpx;
				}
			}
		}

		.content {
			.card_box {
				width: 710rpx;
				background: #FFFFFF;
				margin: 25rpx 20rpx 0 20rpx;
				padding: 20rpx;
				border-radius: 12rpx;
			}
			.underline{
				text-decoration: underline;
			}
			.btn{
				width: 165rpx;
				height: 56rpx;
				border: 1px solid #B5B5B5;
				border-radius: 28rpx;
				color: #666666;
				font-size: 28rpx;
			}
			.info_bottom{
				padding-top: 20rpx;
				border-top: 1px solid #EEEEEE;
				margin-top: 20rpx;
			}
		}
	}
</style>